const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
const baseUrl = require('../controllers/controllers.js').baseUrl;
Page({
  data: {
  	portrait:'',
    mobile:'',
    infodata:'',
  },
  onLoad: function (options) {
  	this.info()
  },
  goPge(){
    wx.navigateTo({ url:'/pages/Me/setPhone'});
  },
  info(){
    Controller.info().then(res=>{
      if(res.data.baseData){
        this.setData({
          infodata:res.data.baseData || '',
          mobile:res.data.baseData.mobile || '',
          portrait:res.data.baseData.portrait || '',
        })
      }
    })
  },
  upShopLogo: function () {
    var that = this;
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: "#222",
      success: function (res) {
        if(!res.cancel) {
          if(res.tapIndex == 0) {
            that.chooseWxImageShop('album');//从相册中选择
          }else if(res.tapIndex == 1) {
            that.chooseWxImageShop('camera');//手机拍照
          }
        }
      }
    })
  },
  chooseWxImageShop: function (type) {
    var that = this;
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: [type],
        success: function (res) {
        console.log(res)
        var img=res.tempFilePaths[0]
        that.picture(img)
      }
    })
  },
  picture(e){
    var that=this;
    wx.uploadFile({
        url: baseUrl+'/upload/picture',
        filePath: e,
        name: "file",
        formData: {
        },
        success: function (res) {
          that.setData({
            portrait:JSON.parse(res.data).data.baseData[0],
          })
          that.comfirm()
        }
    })
  },
  comfirm(e){
    var data={
      portrait:this.data.portrait,
    }
    Controller.updateInfo(data).then(res=>{
      wx.showToast({
        title: "修改成功",
        icon: 'none',
        duration: 1000
      });
    })
    
  },
  onShareAppMessage: function () {

  }
})